package com.lb.shopguide.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lb.shopguide.R;
import com.lb.shopguide.entity.market.TemplateBean;
import com.lb.shopguide.util.pic.ImageLoaderUtils;

import java.util.List;

public class AdapterTemplate extends BaseQuickAdapter<TemplateBean, BaseViewHolder> {
    public AdapterTemplate(int layoutResId, @Nullable List<TemplateBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final TemplateBean item) {
        View view = helper.itemView;
        TextView tvTempName = view.findViewById(R.id.tv_temp_name);
        TextView tvTempTitle = view.findViewById(R.id.tv_temp_title);
        TextView tvUseTemplate = view.findViewById(R.id.tv_use_template);
        ImageView ivIcon = view.findViewById(R.id.iv_temp_icon);

        tvTempName.setText(item.getTemplateName());
        tvTempTitle.setText(item.getTemplateDesc());
        ImageLoaderUtils.displayCircle(mContext, ivIcon, item.getTemplatePicUrl());
        tvUseTemplate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnUseTemplateClickListener != null) {
                    mOnUseTemplateClickListener.onUseTemplateClick(item.getTemplateCode(), item.getTemplateName());
                }
            }
        });

    }

    public interface OnUseTemplateClickListener {
        void onUseTemplateClick(String templateCode, String templateName);
    }

    public void setOnUseTemplateClickListener(OnUseTemplateClickListener listener) {
        this.mOnUseTemplateClickListener = listener;
    }

    private OnUseTemplateClickListener mOnUseTemplateClickListener;
}
